//加载路由配置
import type { RouteRecordRaw } from 'vue-router';
import DefaultIndex from '@/layout/default/index.vue'


const loginUrl = import.meta.env.VITE_APP_LOGIN_PATH || '/login';

// 动态路由容器（初始为空） 由state加载登陆后
const dynamicRoutes: RouteRecordRaw[] = []
// 转换后端路由数据为前端路由格式
// const transformRoutes = (backendRoutes: any[]): RouteRecordRaw[] => {
//   return backendRoutes.map(route => ({
//     path: route.path,
//     name: route.path,
//     component: () => import(route.component),
//     props: true,
//     meta: {
//       title: route.menuName,
//       KeepAlive: true
//     },
//     children: route.children ? transformRoutes(route.children) : [] // 恢复children递归处理
//   }))
// }

// 动态路由设置函数（需导出）
// export const setupDynamicRoutes = async (fetchRoutes: () => Promise<any[]>) => {
//   try {
//     const backendRoutes = await fetchRoutes()
//     dynamicRoutes = transformRoutes(backendRoutes)
// // debugger;
// //     // 将动态路由添加到父路由的children
// //     defaultParentRoute[0].children = dynamicRoutes;
// //     debugger;
//   } catch (error) {
//     console.error('动态路由加载失败:', error)
//     throw error
//   }
// }
// 默认父路由容器
const defaultParentRoute: RouteRecordRaw []= [
  {
    path: '/default-idoo',
    name: 'default-idoo',
    component: DefaultIndex,
    children: [] // 初始为空，由动态路由填充
  }
]
// router.addRoute({
//   path: '/product-list',
//   component: () => import('@/views/product/list/index.vue')
// })
//所有菜单
// const defaultRoutes: RouteRecordRaw[] = [
//   {
//     path: '/default-idoo',
//     name: 'default-idoo',
//     component: DefaultIndex,
//     children: [
//       {
//         path: '/employess-staff',
//         name: 'employess-staff',
//         component: () => import('@/views/employess/staff/worker/index.vue'),
//         props: true,
//         meta: { title: '员工', KeepAlive: true},
//       },
//       {
//         path: '/employess-staff/add',
//         name: 'employess-staff-add',
//         component: () => import('@/views/employess/staff/worker/details/index.vue'),
//         props: true,
//         meta: { title: '新增员工', KeepAlive: true},
//       },
//
//       {
//         path: '/employess/organizational',
//         name: 'employess-organizational',
//         props: true,
//         component: function () {
//           return import('@/views/employess/staff/organizational/index.vue')
//         },
//         meta: { title: '组织结构', KeepAlive: true },
//       },
//       {
//         path: '/employess-department',
//         name: 'employess-department',
//         props: true,
//         component: () => import('@/views/employess/department/index.vue'),
//         meta: { title: '部门', KeepAlive: true },
//       },
//       {
//         path: '/employess/report/skill',
//         name: 'employess-skill',
//         props: true,
//         component: () => import('@/views/employess/report/skill/index.vue'),
//         meta: { title: '技能', KeepAlive: true },
//       }, {
//         path: '/employess/report/authentication',
//         name: 'employess-authentication',
//         props: true,
//         component: () => import('@/views/employess/report/authentication/index.vue'),
//         meta: { title: '认证', KeepAlive: true },
//       },
//       {
//         path: '/document-docmanage',
//         name: 'document-docmanage',
//         component: () => import('@/views/document/manage/index.vue'),
//         props: true,
//         meta: { title: '文档', KeepAlive: true},
//       },
//       {
//         path: '/setting-roles',
//         name: 'setting-roles',
//         component: () => import('@/views/system/role/index.vue'),
//         props: true,
//         meta: { title: '角色', KeepAlive: true},
//       },
//       {
//         path: '/setting-roles/add',
//         name: 'setting-roles-add',
//         component: () => import('@/views/system/role/details/index.vue'),
//         props: true,
//         meta: { title: '新增角色', KeepAlive: true},
//       },
//       {
//         path: '/setting-menus',
//         name: 'setting-menus',
//         component: () => import('@/views/system/menu/index.vue'),
//         props: true,
//         meta: { title: '菜单', KeepAlive: true},
//       },
//       {
//         path: '/setting-menus/add',
//         name: 'setting-menus-add',
//         component: () => import('@/views/system/menu//details/index.vue'),
//         props: true,
//         meta: { title: '新增菜单', KeepAlive: true},
//       },
//       {
//         path: '/setting-company',
//         name: 'setting-company',
//         component: () => import('@/views/system/company/index.vue'),
//         props: true,
//         meta: { title: '公司', KeepAlive: true},
//       },
//       {
//         path: '/setting-system-config',
//         name: 'setting-system-config',
//         component: () => import('@/views/system/config/index.vue'),
//         props: true,
//         meta: { title: '一般设置', KeepAlive: true},
//       },
//       {
//         path: '/setting-system-config/add',
//         name: 'setting-system-config-add',
//         component: () => import('@/views/system/config/details/index.vue'),
//         props: true,
//         meta: { title: '新增参数', KeepAlive: true},
//       },
//       {
//         path: '/setting-user',
//         name: 'setting-user',
//         component: () => import('@/views/system/user/index.vue'),
//         props: true,
//         meta: { title: '用户', KeepAlive: true},
//       },
//       {
//         path: '/setting-user/add',
//         name: 'setting-user-add',
//         component: () => import('@/views/system/user/details/index.vue'),
//         props: true,
//         meta: { title: '新增用户', KeepAlive: true},
//       },
//       {
//         path: '/customer-list',
//         name: 'customer-list',
//         component: () => import('@/views/customer/list/index.vue'),
//         props: true,
//         meta: { title: '客户列表', KeepAlive: true},
//       },
//       {
//         path: '/customer-list/add',
//         name: 'customer-list-add',
//         component: () => import('@/views/customer/list/details/index.vue'),
//         props: true,
//         meta: { title: '新增客户', KeepAlive: true},
//       },
//       {
//         path: '/quotataion-list',
//         name: 'quotataion-list',
//         component: () => import('@/views/quotataion/list/index.vue'),
//         props: true,
//         meta: { title: '报价单', KeepAlive: true},
//       },
//       {
//         path: '/quotation-list/add',
//         name: 'quotation-list-add',
//         component: () => import('@/views/quotataion/list/details/index.vue'),
//         props: true,
//         meta: { title: '新增报价单', KeepAlive: true},
//       },
//       {
//         path: '/product-list',
//         name: 'product-list',
//         component: () => import('@/views/product/list/index.vue'),
//         props: true,
//         meta: { title: '产品', KeepAlive: true},
//       },
//       {
//         path: '/product-list/add',
//         name: 'product-list-add',
//         component: () => import('@/views/product/list/details/index.vue'),
//         props: true,
//         meta: { title: '新增产品', KeepAlive: true},
//       },
//       {
//         path: '/material-list',
//         name: 'material-list',
//         component: () => import('@/views/material/list/index.vue'),
//         props: true,
//         meta: { title: '物料', KeepAlive: true},
//       },
//       {
//         path: '/material-list/add',
//         name: 'material-list-add',
//         component: () => import('@/views/material/list/details/index.vue'),
//         props: true,
//         meta: { title: '新增物料', KeepAlive: true},
//       }
//     ]
//   },
// ];

//主菜单 ; 登录界面路由
const coreRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect:loginUrl
  },
  {
    path: '/main-interface',
    name: 'mainInterface',
    meta: {
      title: '主界面',
      KeepAlive: false,
    },
    component: () => import('@/views/mainInterface/index.vue')
  },
  {
    path: loginUrl,
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },

  //这个后期需要修改 。。。。。。先这么写着
  {
    path: '/:catchAll(.*)', // 使用参数 catchAll 并搭配正则表达式 (.*) 来匹配任意路径
    redirect: loginUrl
  }
];

//导出路由集合
const routes: RouteRecordRaw[] = [
  ...coreRoutes,
  ...defaultParentRoute,
  ...dynamicRoutes
];
export { routes };
